export const manageSort = (list:any,minioUrl:any) => {
    let fCount = 0;
    let sCount = 0;
    let sChild = [];
    let sort = [];
    for (let i = 0; i < list.length; i++) {
        let item = list[i];
        let tItem = null;
        if (item.third_id) {
            tItem = {id: item.third_id, name: item.third_name,
                count: item.third_count, step: 3, pid: null,
                value: item.third_id + "-" + 3};
        }
        if (item.first_id != fCount) {
            let fItem = {
                id: item.first_id,
                name: item.first_name,
                count: item.first_count,
                step: 1,
                children: [],
                value: item.first_id + "-" + 1
            };
            sort.push(fItem);
            fCount = item.first_id;
        }
        if (item.second_id && item.second_id != sCount) {
            sChild = []
            let sItem = {
                id: item.second_id,
                pid: sort[sort.length - 1].id,
                name: item.second_name,
                image: minioUrl + item.second_image,
                step: 2,
                count: item.second_count,
                children: [],
                value: item.second_id + "-" + 2
            };
            sort[sort.length - 1].children.push(sItem);
            sCount = item.second_id;
        }
        if (tItem) {
            sChild.push(tItem);
            let s = sort[sort.length - 1].children;
            tItem.pid = s[s.length - 1].id;
            s[s.length - 1].children = sChild;
        }
    }
    return sort;
}